<template>
	<view>
		<view class="search-box" style="">
			<u-search :focus="true" @search="getInfo()" @custom="getInfo()" placeholder="消息搜索":showAction="true" v-model="search" shape="square"></u-search>
		</view>
		
		<view class="" style="height: 120rpx;">
			
		</view>
		
		
		<view class="item" v-for="item in msg_lsit" @click="handleRemind(item)">
			<image :src="item.avatar" mode=""></image>
			<view class="right">
				<view class="name-time">
					<view class="name">
						{{item.nickname}}
					</view>
		
					<view class="">
						{{item.add_time}}
					</view>
				</view>
		
				<view class="content">
					<text style="color: #3c9cff;">{{'(' + item.name+')'}}</text>
					<text>{{item.content}}</text>
				</view>
			</view>
		</view>
		
		<view class="" style="height: 120rpx;">
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				member_id: '',
				gid: '',
				is_outuser: '',
				msg_lsit:'',
				search:''
			}
		},
		onLoad(val) {
			this.token = uni.getStorageSync('chat_token') || ''
			this.member_id = uni.getStorageSync('chat_member_id') || ''
			this.is_outuser = uni.getStorageSync('chat_is_outuser') || ''
		
		},
		methods: {
			async getInfo() {
				const res = await this.$myRequest({
					url: 'Chat/chat_content_search',
					method: 'POST',
					data: {
						token: this.token,
						member_id: this.member_id,
						is_outuser: this.is_outuser,
						search:this.search,
						company_id:'1'
					},
				});
				if (res.data.code != 200) return uni.showToast({
					title: res.data.datas.msg,
					icon: 'none'
				})
				
				this.msg_lsit = res.data.datas.list
			},
			
			// 点击相关内容
			async handleRemind(item) {
				const res = await this.$myRequest({
					url: 'Chat/is_group_member',
					method: 'POST',
					data: {
						token: this.token,
						member_id: this.member_id,
						gid: item.gid,
						is_outuser: this.is_outuser,
						company_id: '1',
			
					},
				});
				if (res.data.code != 200) return uni.showToast({
					title: res.data.datas.msg,
					icon: 'none'
				})
				
			
				// 已加入该群聊组
				if (res.data.datas.is_group_member == 1) {
					console.log('已加入')
					uni.navigateTo({
						url: 'ChatDetail?gid=' + item.gid + '&comeInfo=1' + '&msgId=' + item.id
					})
				} else {
					uni.showToast({
						title: '未加入该聊天组',
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		padding: 20rpx;
		border-bottom: 1rpx solid #F3F3F3;
		display: flex;
		flex-direction: row;
		align-items: center;
		
		.right {
			.name-time {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				color: #606266;
	
				.name {
					margin-left: 20rpx;
				}
			}
	
			.content {
				width: 560rpx;
	
				margin-left: 10rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
	
		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 12rpx;
		}
	}
	
	
.search-box{
		width: 100%;
		padding: 20rpx;
		
		position: fixed;
		top: 0;
		box-sizing: border-box;
		z-index: 10;
		background-color: #FFFFFF;
		// box-shadow: 1px 3px 15px 0px rgba(3, 70, 126, 0.2);
	}
</style>
